package org.hxzon.workeasy.pages.file;

import java.util.List;

import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SetupRender;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.hxzon.project.SplitPageInfo;
import org.hxzon.workeasy.model.EasyFile;
import org.hxzon.workeasy.pages.base.MyBasePage;
import org.hxzon.workeasy.permissions.FileCRPermissions;
import org.hxzon.workeasy.service.EasyFileService;

public class ListFile extends MyBasePage {
    @Inject
    private EasyFileService fileSer;
    @Property
    private List<EasyFile> list;
    @Property
    private SplitPageInfo page = new SplitPageInfo();

    @OnEvent(value = EventConstants.ACTIVATE)
    Object init(long size, long first) {
        new FileCRPermissions().check(null, getVisitor());
        page.setCurrentPage(first);
        page.setPageSize(size);
        return null;
    }

    @SetupRender
    Object display() {
        page.setRowCount(fileSer.countAll());
        list = fileSer.findAll(page.getCurrentRow(), page.getPageSize());
        return null;
    }

    @OnEvent(value = EventConstants.PASSIVATE)
    Object onPassivate() {
        return new Object[] { page.getPageSize(), page.getCurrentPage() };
    }

}
